
<?php

	session_start();
	
	function ReadUrlLink($link)
	{
		
	$contents = '';
	$v =$link;

	if($v != '')
	
	{
		$url = $v;

		if($url != '')
		{
			$f = fopen($url, "rb");
	
			$contents = '';
		while (!feof($f)) 
			{
				$contents .= fread($f, 8192);
	
			}
			fclose($f);
			$_SESSION["contents"] = $contents;
		}
	}
}
	function ReadUrl()
	{
		
	$contents = '';

	$v = $_POST['arguments']['arg1'];
	
	if($v != '')
	
	{
		$url = $v;

		if($url != '')
		{
			$f = fopen($url, "rb");
	
			$contents = '';
		while (!feof($f)) 
			{
				$contents .= fread($f, 8192);
	
			}
			fclose($f);
			$_SESSION["contents"] = $contents;
		}
	}
}
//======function show screenshoot===========

	function ShowScreenShoot()
	{
		
			$w = '220px';	
			$h = '200px';	
			echo "<style> #Artwork { background: url(".$_SESSION["artwork"].")no-repeat;height:175px;margin-left:35px;
}
#rev{width:245px;
	height:auto;
	background-color:#162851;
	position:relative;
	float:left;
	text-align:center;
	margin-left:256px;
	margin-top:5px;
	margin-bottom:15px;
	}
</style><div id='rev'><div id='Artwork'> <img alt='' src='img/mask175_2.png' style='margin-left:-35px;' /></div><div align='center'><h2>".$_SESSION["GameName"]."</h2></div> <div style='
	font-family:Arial, Helvetica, sans-serif;
		color:#CCC;
		font-size:13px;
		font-weight:bold;
		' align='center'>Size: ".floatval($_SESSION['Size'])." MB</div></div>";
echo "<script type='text/javascript'>document.formUpload.txtTenGame.value = '".$_SESSION["GameName"]."'</script>";
echo "<br/>
 <div style='width:600px; background-color:#0033CC; height:220px; overflow:auto; margin-left:80px; margin-top:10px'>
		<div style='width: 1125px; height: 90px;'>";
		for($i=1;$i<6;$i++)
		{
			if(!empty($_SESSION['img'.$i]))
			{
				echo "<img alt='' src='".$_SESSION["img".$i]."' width='".$w."' height='".$h."' style='margin-left:5px'/>";
			}
		}	
		echo"</div></div>";
		$_SESSION["Show"] = true;
	}
//======function Get screenshoot===========
	function GetScreenShoot()
	{
		$contents = $_SESSION["contents"];
		$mau = '/<div metrics-loc="Swoosh_".*?>([\w\W]*?)<div class="customer-reviews">/i';
			$xuat = '';

		if(preg_match($mau,$contents,$str))
		{
				$xuat = $str[0];
		}
		if(empty($xuat))
		{
			$mau = '/<div metrics-loc="Swoosh_".*?>([\w\W]*?)<div id="left-stack">/i';
			if(preg_match($mau,$contents,$str))
			{
				$xuat = $str[0];
			}
		}
			$start = strpos($xuat,'http');
			$lastE = $end = strpos($xuat,'.jpg');
			$_SESSION["img1"] = substr($xuat,$start,$end-$start+4);
			
			$start = strpos($xuat,'http',$lastE);
			$lastE = $end = strpos($xuat,'.jpg',$start);
			$_SESSION["img2"] = substr($xuat,$start,$end-$start+4);
			
			
			$start = strpos($xuat,'http',$lastE);
			$lastE = $end = strpos($xuat,'.jpg',$start);
			$_SESSION["img3"] = substr($xuat,$start,$end-$start+4);
			
			
			$start = strpos($xuat,'http',$lastE);
			$lastE = $end = strpos($xuat,'.jpg',$start);
			$_SESSION["img4"] = substr($xuat,$start,$end-$start+4);
			
			
			$start = strpos($xuat,'http',$lastE);
			$lastE = $end = strpos($xuat,'.jpg',$start);
			$_SESSION["img5"] = substr($xuat,$start,$end-$start+4);
	}
//========Get Artwork==============
	function GetArtworkAndName()
	{
		$contents = $_SESSION["contents"];
		$mau = '/<img width="175" height="175".*?>([\w\W]*?)/i';
		$xuat = '';
		if(preg_match($mau,$contents,$str))
	    	{$xuat = $str[0];}
		if(empty($xuat))
		{
			echo '';
		}
		else
		{
			$start = strpos($xuat,'http');
			$end = strpos($xuat,'jpg');
			$_SESSION["artwork"] = substr($xuat,$start,$end-$start+3);  
		}
		$mau = '/<div id="title".*?>([\w\W]*?)<\/div>/i';
		$xuat = '';
		if(preg_match($mau,$contents,$str))
		{
			$xuat = $str[0];
		}
			$start = strpos($xuat,'<h1>');
			$end = strpos($xuat,'</h1>');
			$_SESSION["GameName"] = trim(substr($xuat,$start,$end-$start));
			$_SESSION["GameName"] = str_replace("#","-",$_SESSION["GameName"]);
			$_SESSION["GameName"] = str_replace("<h1>","",$_SESSION["GameName"]);
			$_SESSION["GameName"] = str_replace("</h1>","",$_SESSION["GameName"]);
			//===get size game================
			$mau = '/<ul class="list"><li>([\w\W]*?)<\/ul>/i';
			$xuat = '';
		if(preg_match($mau,$contents,$str))
		{
			$xuat = $str[0];
		}
		$start = strpos($xuat,'Size:') + 13;
			$end = strpos($xuat,'MB</li>',$start);
			$str = trim(substr($xuat,$start,$end-$start));
			$_SESSION["Size"] = (float)$str;
	}
	
		if(isset($_POST["arguments"]))
		{ReadUrl();
		//==============get artwork and game name=========================
		GetArtworkAndName();
		
		//===================get screenshoot=========================	
		GetScreenShoot();
		ShowScreenShoot();
		}
	
			
?>
